package org.jz.gae.redbook.spb.server.controller;

import java.util.Date;

import org.jz.gae.redbook.spb.server.helper.EvidenceHelper;
import org.jz.gae.redbook.spb.shared.EvidenceEntityView;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

public class EvidenceUtils
{
	public static void reflectEntityToView(
			Entity evidence,
			EvidenceEntityView newEvidence)
	{
		newEvidence.setEvidenceKey(KeyFactory.keyToString(evidence.getKey()));
		//newEvidence.setEvidenceSpeciesKey(KeyFactory.keyToString((Key)evidence.getProperty(EvidenceHelper.EVIDENCE_SPECIES_KEY))); 
		newEvidence.setEvidenceLocationKey(KeyFactory.keyToString((Key)evidence.getProperty(EvidenceHelper.EVIDENCE_LOCATION_KEY)));
		newEvidence.setEvidenceType((String) evidence.getProperty(EvidenceHelper.EVIDENCE_TYPE));
		newEvidence.setEvidencePopulation((String) evidence.getProperty(EvidenceHelper.EVIDENCE_POPULATION));
		newEvidence.setEvidenceCondition((String) evidence.getProperty(EvidenceHelper.EVIDENCE_CONDITION));
		newEvidence.setEvidencePattern((String) evidence.getProperty(EvidenceHelper.EVIDENCE_PATTERN));
		//newEvidence.setEvidenceState((String) evidence.getProperty(EvidenceHelper.EVIDENCE_STATE));
		//newEvidence.setEvidenceInitialData((String) evidence.getProperty(EvidenceHelper.EVIDENCE_INITIAL_DATA));
		newEvidence.setEvidenceDescription((String) evidence.getProperty(EvidenceHelper.EVIDENCE_DESCRIPTOION));
		newEvidence.setEvidenceCenose((String) evidence.getProperty(EvidenceHelper.EVIDENCE_CENOSE));
		newEvidence.setEvidencePhenology((String) evidence.getProperty(EvidenceHelper.EVIDENCE_PHENOLOGY));
		newEvidence.setEvidenceQuantityPlain((String) evidence.getProperty(EvidenceHelper.EVIDENCE_QUANTITY_PLAIN));
		newEvidence.setEvidenceSquare((String) evidence.getProperty(EvidenceHelper.EVIDENCE_SQUARE));
		newEvidence.setEvidenceDate((Date) evidence.getProperty(EvidenceHelper.EVIDENCE_DATE));
		newEvidence.setEvidenceSpecificExistingThreats((String) evidence.getProperty(EvidenceHelper.EVIDENCE_SPECIFIC_EXISTING_THREATS));
		newEvidence.setEvidenceSpecificPotentialThreats((String) evidence.getProperty(EvidenceHelper.EVIDENCE_SPECIFIC_POTENTIAL_THREATS));
		newEvidence.setEvidenceDescriptor((String) evidence.getProperty(EvidenceHelper.EVIDENCE_DESCRIPTOR));
		newEvidence.setEvidenceNote((String)evidence.getProperty(EvidenceHelper.EVIDENCE_NOTE));
	}
	
	public static void reflectViewToEntity(
			EvidenceEntityView _EvidenceToEdit,
			Entity evidence)
	{
		evidence.setProperty(EvidenceHelper.EVIDENCE_LOCATION_KEY, _EvidenceToEdit.getEvidenceLocationKey());
		evidence.setProperty(EvidenceHelper.EVIDENCE_TYPE, _EvidenceToEdit.getEvidenceType());
		evidence.setProperty(EvidenceHelper.EVIDENCE_POPULATION, _EvidenceToEdit.getEvidencePopulation());
		evidence.setProperty(EvidenceHelper.EVIDENCE_CONDITION, _EvidenceToEdit.getEvidenceCondition());
		evidence.setProperty(EvidenceHelper.EVIDENCE_PATTERN, _EvidenceToEdit.getEvidencePattern());
		evidence.setProperty(EvidenceHelper.EVIDENCE_DESCRIPTOION, _EvidenceToEdit.getEvidenceDescription());
		evidence.setProperty(EvidenceHelper.EVIDENCE_CENOSE, _EvidenceToEdit.getEvidenceCenose());
		evidence.setProperty(EvidenceHelper.EVIDENCE_PHENOLOGY, _EvidenceToEdit.getEvidencePhenology());
		evidence.setProperty(EvidenceHelper.EVIDENCE_QUANTITY_PLAIN, _EvidenceToEdit.getEvidenceQuantityPlain());
		evidence.setProperty(EvidenceHelper.EVIDENCE_SQUARE, _EvidenceToEdit.getEvidenceSquare());
		evidence.setProperty(EvidenceHelper.EVIDENCE_DATE, _EvidenceToEdit.getEvidenceDate());
		evidence.setProperty(EvidenceHelper.EVIDENCE_SPECIFIC_EXISTING_THREATS, _EvidenceToEdit.getEvidenceSpecificExistingThreats());
		evidence.setProperty(EvidenceHelper.EVIDENCE_SPECIFIC_POTENTIAL_THREATS, _EvidenceToEdit.getEvidenceSpecificPotentialThreats());
		evidence.setProperty(EvidenceHelper.EVIDENCE_DESCRIPTOR, _EvidenceToEdit.getEvidenceDescriptor());
		evidence.setProperty(EvidenceHelper.EVIDENCE_NOTE, _EvidenceToEdit.getEvidenceNote());
	}

	

}
